# import os
from pathlib import Path
# import struct
# import sys
import urllib
from urllib.parse import quote

from flask import Flask, jsonify, request, json, Response, send_file
from flask import send_from_directory, make_response
# import flask.helpers
from flask_apscheduler import APScheduler
from flask_cors import CORS

from common.public import *
from config import *
# from view import questionbankview
from view.allappview import AllAppView
from view.aouthview import AouthView
from view.applicantdetailsview import ApplicantDetailsView
from view.areaview import AreaView
from view.borrowview import BorrowView
from view.customerview import CustomerView
from view.deptview import DeptView
from view.discountlistview import DisCountListView
from view.documentview import DocumentView
from view.expenseformview import ExpenseFormView
from view.gongshangview import GongShangView
from view.helpjsonview import HelpJsonView
from view.innerworkorderview import InnerWorkOrderView
from view.keepaccountview import KeepAccountView
from view.lotteryview import LotteryView
from view.mycustomerview import MyCustomerView
from view.myregistratorview import MyRegistratorView
from view.notifyview import NotifyView
from view.payformview import PayFormView
from view.questionbankview import QuestionBankView
from view.registrationsheetview import RegistrationSheetView
from view.serviceview import ServiceView
from view.ststitrackview import StstitrackView
from view.supplierview import SupplierView
from view.teamview import TeamView
from view.testpaperview import TestPaperView
from view.testview import TestView
from view.trackrecordview import TrackRecordView
from view.transformdetailview import TransFormDetailView
from view.transformrecorderview import TransFormRecorderView
from view.transformview import TransFormView
from view.userview import UserView
from view.workorderview import WorkOrderView
from view.positionview import PositionView
from view.approvalview import ApprovalView
from view.personalsalesview import PersonalSalesView
from view.authoritymanagementview import AuthorityManagementView
from view.invoicecompanyview import InvoiceCompanyView

app = Flask(__name__)
app.config.from_object(Config())  # 为实例化的flask引入配置

# 全局跨域
CORS(app, supports_credentials=True)


@app.route('/essc/db/<index>/<type>/<filename>', methods=['POST'])
def create(index, doctype, filename):
    ''' 写入文件'''
    result = {"code": 100, "msg": "写入文件失败。", "data": {}}
    file_path = BASE_PATH + index + "/" + doctype + "/" + filename
    data = json.dumps(request.json, indent=4, ensure_ascii=False)
    try:
        fh = open(file_path, "w")
        fh.write(data)
        result = {"code": 200, "msg": "写入文件成功。", "data": request.json}
    except IOError:
        print(file_path + "写入文件失败")
    fh.close()

    return jsonify(result)


@app.route('/essc/db/<index>/<doctype>/<filename>', methods=['GET'])
def get(index, doctype, filename):
    ''' 读取文件 '''
    # 验证TOKEN
    #     aouth = auouthCheck(request.headers.get('Token'),
    #                         request.headers.get('UserID'),
    #                         request.headers.get('CurHtml'))
    #     if aouth['code']==200:
    file_path = BASE_PATH + index + "/" + doctype + "/" + filename
    if os.path.exists(file_path):
        fh = open(file_path, "r")
        result = {"code": 200, "message": "读取成功！", "data": json.loads(fh.read())}

    fh.close()
    #     else:
    #         return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/action/login', methods=['POST'])
def login():
    ''' 登录 '''
    uv = UserView()
    result = uv.login(request.json['username'], request.json['password'])
    return jsonify(result)


@app.route('/essc/api/app/<userid>', methods=['GET'])
def getUserApp(userid):
    '''用户应用程序取得 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        uv = UserView()
        result = uv.getUserApp(userid)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/user', methods=['POST'])
def getUsers():
    '''根据部门，主管取得用户 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        uv = UserView()
        result = uv.getUsers(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/allapp', methods=['GET'])
def getAllApp():
    '''所有应用程序取得 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        av = AllAppView()
        result = av.getAllApp()
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/user/all', methods=['get'])
def getAllUsers():
    '''取得所有用户 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        uv = UserView()
        result = uv.getAllUsers()
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/leader/all', methods=['get'])
def getAllleader():
    '''取得所有主管 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        uv = UserView()
        result = uv.getAllLeader()
        print(result)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/userleader/dept', methods=['POST'])
def getUserLeader():
    '''取得使用者主管 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        uv = UserView()
        result = uv.getUserLeader(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/leader/dept', methods=['POST'])
def getLeader():
    '''取得所有主管 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        uv = UserView()
        result = uv.getLeader(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/user/query', methods=['POST'])
def queryUsers():
    '''查询用户 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        uv = UserView()
        result = uv.queryUsers(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/user/add', methods=['PUT'])
def addUser():
    ''' 添加 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        uv = UserView()
        result = uv.addUser(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/user/update', methods=['PUT'])
def updateUser():
    ''' 更新 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        uv = UserView()
        result = uv.updateUser(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/user/delete', methods=['PUT'])
def deleteUser():
    ''' 删除 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        uv = UserView()
        result = uv.deleteUser(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/alldept', methods=['GET'])
def getAllDept():
    '''所有部门列表取得 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        av = DeptView()
        result = av.getAllDept()
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/allgroups', methods=['GET'])
def getAllGroups():
    '''所有分组列表取得 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        av = DeptView()
        result = av.getGroups()
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/detp/combination', methods=['GET'])
def getCombination():
    '''组织取得 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = DeptView()
        result = view.getCombination()
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/image/download/icon/<filename>', methods=['GET'])
def downloadIcon(filename):
    """下载证件照"""
    filename = urllib.parse.unquote(filename)

    # 验证TOKEN
    #     aouth = AouthView().auouthCheck(token)
    if True:
        mdict = {
            'jpeg': 'image/jpeg',
            'jpg': 'image/jpeg',
            'png': 'image/png',
            'gif': 'image/gif'
        }
        mime = mdict[filename.split('.')[1].lower()]
        path = UPLOAD_PATH + "/" + UPLOAD_ICON_PATH + "/" + filename
        if not os.path.exists(path):
            # Res 是我自己定义的返回类，raw方法将数据组成字典返回
            return jsonify('image does not exists')
        with open(path, 'rb') as f:
            image = f.read()
        resp = Response(image, mimetype=mime)
        return resp
    else:
        return jsonify('image does not exists')


@app.route('/essc/api/image/download/gongshang/<id>/<filename>/<token>', methods=['GET'])
def downloadGongshang(id, filename, token):
    """下载"""
    filename = urllib.parse.unquote(filename)

    # 验证TOKEN
    aouth = AouthView().auouthCheck(token)
    if aouth['code'] == 200:
        mdict = {
            'jpeg': 'image/jpeg',
            'jpg': 'image/jpeg',
            'png': 'image/png',
            'gif': 'image/gif'
        }
        mime = mdict[filename.split('.')[1].lower()]
        path = UPLOAD_PATH + "/" + UPLOAD_GONGSHANG_PATH + "/" + id + "/" + filename
        if not os.path.exists(path):
            # Res 是我自己定义的返回类，raw方法将数据组成字典返回
            return jsonify('image does not exists')
        with open(path, 'rb') as f:
            image = f.read()
        resp = Response(image, mimetype=mime)
        return resp
    else:
        return jsonify(aouth)


@app.route('/essc/api/image/download/idcard/<userid>/<filename>/<token>', methods=['GET'])
def downloadIdcard(userid, filename, token):
    """下载证件照"""
    filename = urllib.parse.unquote(filename)

    # 验证TOKEN
    aouth = AouthView().auouthCheck(token)
    if aouth['code'] == 200:
        mdict = {
            'jpeg': 'image/jpeg',
            'jpg': 'image/jpeg',
            'png': 'image/png',
            'gif': 'image/gif'
        }
        mime = mdict[filename.split('.')[1].lower()]
        path = UPLOAD_PATH + "/" + UPLOAD_IDCARD_PATH + "/" + userid + "/" + filename
        if not os.path.exists(path):
            # Res 是我自己定义的返回类，raw方法将数据组成字典返回
            return jsonify('image does not exists')
        with open(path, 'rb') as f:
            image = f.read()
        resp = Response(image, mimetype=mime)
        return resp
    else:
        return jsonify(aouth)


@app.route('/essc/api/image/upload/<type>/<userid>', methods=['POST'])
def uploadIdcard(type, userid):
    """上传"""
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        if request.method == 'POST' and 'file' in request.files:
            file = request.files['file']
            path = UPLOAD_PATH + "/" + type + "/" + userid + "/"
            filename = path + file.filename
            my_path = Path(path)
            if not my_path.exists():
                # 指定的文件或目录不存在:
                os.makedirs(path)
        file.save(filename)
        return jsonify({"code": 200,
                        "message": "上传成功！",
                        "data": {"name": file.filename,
                                 "url": API_IMAGE_DOWNLOAD + type + "/" + userid + "/" + file.filename}})
    else:
        return jsonify(aouth)


# @app.route('/essc/api/image/updoad', methods=['POST'])
# def upload_file():
# #     base = BaseView()
# #     return jsonify(base.upload(request))
#     import base64
#     if request.method == 'POST' and 'file' in request.files:
#         file= request.files['file']
#         base64_data = base64.b64encode(file.read())
#     return base64_data

# @app.route('/essc/api/image/<imageid>', methods=['GET'])
# def getImage(imageid):
#     import base64
#     image = open("D:/phpstudy_pro/WWW/essc/service/upload/images/20200309022734240.jpg", 'rb')
#     base64_data = base64.b64encode(image.read())
#     return base64_data

@app.route('/essc/api/gongshangzhuce/query', methods=['POST'])
def queryGongShangZhuCe():
    '''查询 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = GongShangView()
        result = view.queryGongShang(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/gongshangzhuce/update', methods=['PUT'])
def updateGongShangZhuCe():
    ''' 更新 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = GongShangView()
        result = view.updateGongShang(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/gongshangzhuce/add', methods=['PUT'])
def addGongShangZhuCe():
    ''' 添加 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = GongShangView()
        result = view.addGongShang(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/gongshangzhuce/delete', methods=['PUT'])
def deleteGongShangZhuCe():
    ''' 删除 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = GongShangView()
        result = view.deleteGongShang(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/tracker/<userid>', methods=['get'])
def getTrackers(userid):
    '''取得主管所有的跟踪者 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        mv = MyCustomerView()
        result = mv.getTrackers(userid)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/mycus/query', methods=['POST'])
def queryMyCustomer():
    '''查询用户 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        mv = MyCustomerView()
        result = mv.queryMyCustomer(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/mycus/add', methods=['PUT'])
def addMyCustomer():
    ''' 添加 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = MyCustomerView()
        result = view.addMyCustomer(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/mycus/update', methods=['PUT'])
def updateMyCustomer():
    ''' 更新 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = MyCustomerView()
        result = view.updateMyCustomer(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/mycus/moveto', methods=['PUT'])
def movetoMyCustomer():
    ''' 客户转移到公共客户或他人 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = MyCustomerView()
        result = view.moveto(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/mycus/getoutdate', methods=['PUT'])
def getOutdate():
    '''  捡漏  '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = MyCustomerView()
        result = view.getoutdate(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/mycus/typeto', methods=['PUT'])
def typetoMyCustomer():
    ''' 批量客户分类 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = MyCustomerView()
        result = view.typeto(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/trackrecord/add', methods=['PUT'])
def addTrackRecord():
    ''' 添加 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = TrackRecordView()
        result = view.addTrackRecord(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/mycus/addrandom', methods=['PUT'])
def addFromCustomerRandom():
    ''' 随机添加 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = MyCustomerView()
        result = view.addFromCustomerRandom(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/customer/query', methods=['POST'])
def queryCustomer():
    '''查询公共客户 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        mv = CustomerView()
        result = mv.query(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/customer/add', methods=['PUT'])
def addCustomer():
    ''' 添加 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = CustomerView()
        result = view.add(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/customer/update', methods=['PUT'])
def updateCustomer():
    ''' 更新 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = CustomerView()
        result = view.update(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/customer/assigne', methods=['PUT'])
def assigneCustomer():
    ''' 更新 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = CustomerView()
        result = view.assigne(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/customer/delete', methods=['PUT'])
def deleteCustomer():
    ''' 删除 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        uv = CustomerView()
        result = uv.delete(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/customer/import/<src>', methods=['POST'])
def importCustomer(src):
    """导入公共客户"""
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = CustomerView()
        result = view.importCustomer(request, src)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/notify/query', methods=['POST'])
def queryNotify():
    '''查询通知 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = NotifyView()
        result = view.query(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/notify/update', methods=['PUT'])
def updateNotify():
    ''' 更新 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = NotifyView()
        result = view.update(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/transform/query', methods=['POST'])
def queryTransForm():
    '''查询流转单 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = TransFormView()
        result = view.query(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/transform/add', methods=['PUT'])
def addTransForm():
    ''' 添加 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = TransFormView()
        result = view.add(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/transform/nopass', methods=['PUT'])
def nopassTransForm():
    '''驳回流转单 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = TransFormView()
        result = view.nopass(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/transform/audit', methods=['PUT'])
def auditTransForm():
    '''审核流转单 '''
    # 验证TOKEN
    print(request.json)
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = TransFormView()
        result = view.update(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/transform/download/<id>/<token>', methods=['GET'])
def downloadTransForm(id, token):
    '''下载流转单 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(token)
    if aouth['code'] == 200:
        dirpath = DOWNLOAD_PATH + "/" + DOWNLOAD_PATH_TRANSFORM + "/"
        filename = DOWNLOAD_PATH_TRANSFORM_XLSX.format(id=id)
        return send_from_directory(dirpath, filename, as_attachment=True)
    else:
        return jsonify(aouth)


@app.route('/essc/api/team/member/<leaderid>', methods=['get'])
def getMembers(leaderid):
    '''总经办取得所有用户  部门经理取得部门用户'''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = TeamView()
        result = view.getMembers(leaderid)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/area/list', methods=['get'])
def getAreas():
    '''取得区域列表 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = AreaView()
        result = view.getAreas()
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/area/add/<areaname>', methods=['PUT'])
def addArea(areaname):
    ''' 添加 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        uv = AreaView()
        result = uv.addArea(areaname)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/ststitrack/query', methods=['POST'])
def ststiTrack():
    '''跟踪信息统计 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = StstitrackView()
        result = view.query(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


# 定时任务
def task_expire():
    """定时任务：处理过期我的客户"""
    view = MyCustomerView()
    res = view.expireCustomer()


# add cth 2020年11月6日13:30:39 start
# 增加招聘信息录入功能
# add
@app.route('/essc/api/registration/add', methods=['PUT'])
def addRegistration():
    ''' 添加 '''
    uv = RegistrationSheetView()
    result = uv.addRegistration(request.json)
    return jsonify(result)


# end
@app.route('/essc/api/registration/update', methods=['PUT'])
def updateRegistration():
    ''' 后续修改'''
    uv = ApplicantDetailsView()
    result = uv.updateRegistration(request.json)
    return jsonify(result)


# end
# add cth 2020年11月10日14:03:39 start
# 增加招聘信息身份证检查功能
# add
@app.route('/essc/api/registration/query', methods=['POST'])
def checkRegistration():
    ''' 检查'''
    uv = RegistrationSheetView()
    result = uv.checkRegistration(request.json)
    return jsonify(result)


# end


# add cth 2020年11月24日14:03:39 start
# 增加显示所有信息功能
# add
@app.route('/essc/api/registration/querylist', methods=['POST'])
def queryRegistration():
    ''' 显示所有信息 '''
    uv = MyRegistratorView()
    result = uv.queryMyRegistor(request.json)
    return jsonify(result)


# end


# add cth 2020年11月27日10:54:56
# 增加更新应聘备注
# start
@app.route('/essc/api/myregistrator/update', methods=['PUT'])
def myregistratorUpdate():
    ''' updateinformation '''
    uv = MyRegistratorView()
    result = uv.updateMyRegistor(request.json)
    return jsonify(result)


# end


# add cth 2020年12月1日09:20:24 start
# 查询题库功能
# add
@app.route('/essc/api/questionbankview/querylist', methods=['POST'])
def queryQuestionBank():
    ''' 显示题目信息 '''
    uv = QuestionBankView()
    result = uv.queryQuestionBank(request.json)
    print(request.json)
    return jsonify(result)


# add cth 2020年12月1日09:20:24 start
# 新增题库功能
# add
@app.route('/essc/api/questionbankview/add', methods=['PUT'])
def addQuestionBank():
    ''' 增加题目信息 '''
    uv = QuestionBankView()
    print(request.json)
    result = uv.addQuestionBank(request.json)
    return jsonify(result)


# end


# add cth 2020年12月1日10:17:27 start
# 增加修改题库功能
# add
@app.route('/essc/api/questionbankview/edit', methods=['PUT'])
def updateQuestionBank():
    ''' 修改题目信息 '''
    uv = QuestionBankView()
    result = uv.updateQuestionBank(request.json)
    print(result)
    return jsonify(result)


# end


# add cth 2020年12月1日13:26:50 start
# 增加查询试卷功能
# add
@app.route('/essc/api/testpaperview/querylist', methods=['POST'])
def queryTestPaper():
    ''' 显示所有试卷信息 '''
    uv = TestPaperView()
    result = uv.queryTest(request.json)
    return jsonify(result)


# add cth 2020年12月1日16:57:29 start
# 增加修改试卷基本信息功能
# add
@app.route('/essc/api/testpaperview/edit', methods=['PUT'])
def updateTestPaper():
    ''' 修改试卷信息 '''
    uv = TestPaperView()
    result = uv.updateQuestionBank(request.json)
    return jsonify(result)


# add cth 2020年12月2日09:25:00 start
# 增加读入个人试卷功能
# add
@app.route('/essc/api/testpaperview/read', methods=['POST'])
def queryPersonTestPaper():
    ''' 显示个人试卷'''
    uv = TestPaperView()
    result = uv.read(request.json)
    return jsonify(result)


# end


# add cth 2020年12月2日14:19:40 start
# 增加随机生成试卷功能
# add
@app.route('/essc/api/testpaperview/addpaper', methods=['PUT'])
def addTestPaper():
    ''' 随机生成试卷 '''
    uv = TestPaperView()
    result = uv.addPaperTest(request.json)
    return jsonify(result)


# add cth 2020年12月2日17:06:52
# 增加答题保存功能
# start
@app.route('/essc/api/testpaperview/save', methods=['PUT'])
def testSave():
    ''' save test '''
    uv = TestPaperView()
    result = uv.save(request.json)
    return jsonify(result)


# end
# add cth 2020年12月1日16:57:29 start
# 增加修改试卷基本信息功能
# add
@app.route('/essc/api/testpaperview/remove', methods=['POST'])
def removeTestPaper():
    ''' 删除试卷 '''
    uv = TestPaperView()
    result = uv.removeQuestionBank(request.json)
    print(result)
    return jsonify(result)


@app.route('/essc/api/supplier/delete', methods=['PUT'])
def deleteSupplier():
    ''' 删除供应商'''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = SupplierView()
        result = view.delete(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/service/get', methods=['GET'])
def getServices():
    ''' 取得服务项目'''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = SupplierView()
        result = view.getServices()
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/servicedetail/get/<id>', methods=['GET'])
def getServicesDetail(id):
    ''' 取得服务项目明细'''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = SupplierView()
        result = view.getServicesDetail(id)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/transformdetail/add', methods=['PUT'])
def addTransFormDetail():
    '''添加服务信息 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = TransFormDetailView()
        result = view.add(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/transformdetail/update', methods=['PUT'])
def updateTransFormDetail():
    '''更新服务信息 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = TransFormDetailView()
        result = view.update(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/transformdetail/delete', methods=['PUT'])
def deleteTransFormDetail():
    ''' 删除服务'''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = TransFormDetailView()
        result = view.delete(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/notify/batch', methods=['PUT'])
def batchNotify():
    ''' 批量处理通知'''
    view = NotifyView()
    result = view.batch(request.json)
    return jsonify(result)


@app.route('/essc/api/lottery/add', methods=['PUT'])
def addLottery():
    '''添加奖信息 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = LotteryView()
        result = view.add(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/lottery/update', methods=['PUT'])
def editLottery():
    '''编辑奖信息 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = LotteryView()
        result = view.update(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/lottery/getnumber/<id>/<token>', methods=['GET'])
def getLotteryNumber(id, token):
    '''得到抽奖次数 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(token)
    if aouth['code'] == 200:
        view = LotteryView()
        result = view.getLotteryNumber(id)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/lottery/getlottery/<id>/<token>', methods=['GET'])
def getLottery(id, token):
    '''抽奖 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(token)
    if aouth['code'] == 200:
        view = LotteryView()
        result = view.getLottery(id)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/lottery/query', methods=['POST'])
def queryLottery():
    '''查询抽奖信息 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = LotteryView()
        result = view.query(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/supplier/query', methods=['POST'])
def querySupplier():
    '''查询供应商信息 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = SupplierView()
        result = view.query(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/supplier/add', methods=['PUT'])
def addSupplier():
    '''添加供应商信息 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = SupplierView()
        result = view.add(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/supplier/update', methods=['PUT'])
def updateSupplier():
    '''更新供应商信息 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = SupplierView()
        result = view.update(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/supplier/adddetail', methods=['PUT'])
def addSupplierDetail():
    '''添加供应商信息 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = SupplierView()
        result = view.addDetail(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/supplier/updatedetail', methods=['PUT'])
def updateSupplierDetail():
    '''更新供应商信息 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = SupplierView()
        result = view.updateDetail(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


# @app.route('/essc/api/transform/annex/<filename>', methods = ['GET'])
# def downloadTransFormAnnex(filename):  # token
#      """下载流转单附件"""
#      print(filename)
#      # 验证TOKEN
#  #     aouth = AouthView().auouthCheck(token)
#  #     if aouth['code']==200:
#      dirpath = UPLOAD_PATH + "/transform/annex/"
#      print(filename)
#      print(dirpath)
#      print(send_from_directory(dirpath, filename, as_attachment = True))
#      print(make_response(send_from_directory(dirpath, filename, as_attachment = True)))
#      return send_from_directory(dirpath, filename, as_attachment = True)
#  #     else:
#  #         return jsonify(aouth)
@app.route('/essc/api/transform/annex/download', methods=["post"])
def downloadTransFormAnnex():
    '''下载附件 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.json["token"])  # request.json["params"]["token"]
    if aouth['code'] == 200:
        filename = request.json["downloadname"]  # 文件名
        filepath = DOWNLOAD_PATH_TRANSFORM_ANNEX1
        filepath = filepath + '/' + filename
        res = make_response(send_file(filepath))
        # 自定义的一个header，方便前端取到名字
        res.headers['filename'] = quote(filename.encode('utf-8'))
        return res

    else:
        return jsonify(aouth)


@app.route('/essc/api/transform/annex/upload/<id>', methods=['POST'])
def uploadTransFormAnnex(id):
    """上传流转单附件"""
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        if request.method == 'POST' and 'file' in request.files:
            file = request.files['file']
            mime = file.filename.split('.')[1].lower()
            path = UPLOAD_PATH + "/transform/annex/"
            filename = path + id + "." + mime
            returnname = id + "." + mime
            my_path = Path(path)
            if not my_path.exists():
                # 指定的文件或目录不存在:
                os.makedirs(path)
        file.save(filename)
        return jsonify({"code": 200,
                        "message": "上传成功！",
                        # "data":{"name":file.filename,"url":API_TRANSFORM_ANNEX_DOWNLOAD +id+"." + mime}})
                        "data": {"name": returnname, "url": API_TRANSFORM_ANNEX_DOWNLOAD + id + "." + mime,
                                 "mine": mime}})
    else:
        return jsonify(aouth)


# add cth 2020年12月15日14:32:17 start
# 读取json功能
# add
@app.route('/essc/api/help/load', methods=['POST'])
def readJson():
    ''' 读取json '''
    uv = HelpJsonView()
    result = uv.read()
    return jsonify(result)


# end


# add cth 2020年12月18日13:48:47
# 复制应骋人员信息，方便添加用户。
# start
@app.route('/essc/api/myregistrator/adduser', methods=['post'])
def myregistratorAddUser():
    ''' 复制应骋人员信息，方便添加用户 '''
    uv = MyRegistratorView()
    result = uv.adduser(request.json)
    return jsonify(result)


# end


# add cth 2020年12月29日10:03:46 start
# 增加查询考试功能
# add
@app.route('/essc/api/test/querylist', methods=['POST'])
def queryTest():
    ''' 显示考试信息 '''
    uv = TestView()
    result = uv.queryTest(request.json)
    return jsonify(result)


# end


# add cth 2020年12月29日11:43:53 start
# 增加添加考试 功能
# add
@app.route('/essc/api/test/add', methods=['PUT'])
def addTest():
    ''' 添加考试信息 '''
    uv = TestView()
    result = uv.addTest(request.json)
    return jsonify(result)


# end
@app.route('/essc/api/deptuser/query', methods=['POST'])
def queryManyUsers():
    '''查询用户 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        uv = UserView()
        result = uv.queryDeptUsers(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


# add cth 2020年12月31日15:16:22 start
# 增加删除考试信息功能
# add
@app.route('/essc/api/test/remove', methods=['POST'])
def removeTest():
    ''' 删除考试 '''
    uv = TestView()
    result = uv.removeTest(request.json)
    print(result)
    return jsonify(result)


# add cth 2021年1月4日11:39:48 start
# 增加考试开始功能
# add
@app.route('/essc/api/test/start', methods=['PUT'])
def startTest():
    ''' 开始考试 '''
    uv = TestView()
    result = uv.startTest(request.json)
    print(result)
    return jsonify(result)


# add cth 2021年1月4日17:29:54 start
# 增加查询试卷功能
# add
@app.route('/essc/api/testpaperview/phonequerylist', methods=['POST'])
def queryPhoneTestPaper():
    ''' 显示所有试卷信息 '''
    uv = TestPaperView()
    result = uv.queryPhoneTest(request.json)
    return jsonify(result)


# end
# update cth 2021年2月20日10:27:38 start
# 修改添加工单代理记账服务信息 功能
@app.route('/essc/api/transformdetail/assignment', methods=['post'])
def assignmentTransFormDetail():
    '''添加工单代理记账服务信息 '''
    # 验证TOKEN
    print(request.json)
    data = []
    view = TransFormDetailView()
    result = view.createdocument(request.json)
    documentId = result["data"][0]
    result = view.updatestatus(request.json)
    for item in request.json:
        if item["name"] == AGENTKEEPING:
            result = view.aggentkeeping(item, documentId)
        else:
            result = view.assignment(item, documentId)
        data.append(result)
    return jsonify(data)


# end


# add cth 2021年1月18日10:40:40 start
# 增加显示工单信息功能
@app.route('/essc/api/workorder/querylist', methods=['POST'])
def queryWorkOrder():
    ''' 显示工单信息 '''
    uv = WorkOrderView()
    result = uv.queryWorkOrder(request.json)
    return jsonify(result)


# end
# add cth 2021年1月18日17:12:21 start
# 增加取得服务名称功能
@app.route('/essc/api/service/servicename', methods=['get'])
def getServiceName():
    '''取得服务名称 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = ServiceView()
        result = view.getServiceName()
    else:
        return jsonify(aouth)
    return jsonify(result)


# end
# add cth 2021年1月18日17:12:21 start
# 增加取得服务名称功能
# @app.route('/essc/api/service/handleitem', methods = ['get'])
# def getHandleItem():
#     '''取得待办事项 '''
#     # 验证TOKEN
#     aouth = AouthView().auouthCheck(request.headers.get('Token'))
#     if aouth['code'] == 200:
#         view = ServiceView()
#         result = view.getHandleItem()
#     else:
#         return jsonify(aouth)
#     return  jsonify(result)
# end
# add 2021年1月19日09:33:07 start
# 增加修改在分配功能
@app.route('/essc/api/workorder/edit', methods=['put'])
def editWorkOrder():
    ''' 工单重新分配修改 '''
    uv = WorkOrderView()
    result = uv.distributeWorkOrder(request.json)
    return jsonify(result)


# end
# add 2021年1月19日13:22:33 start
# 增加新增工单详情数据
@app.route('/essc/api/workorder/additem', methods=['post'])
def addWorkOrderItem():
    ''' 新增工单详情数据 '''
    uv = WorkOrderView()
    result = uv.addWorkOrderItem(request.json)
    return jsonify(result)


# end
# add 2021年1月19日13:22:33 start
# 增加新增工单详情数据
@app.route('/essc/api/workorder/edititem', methods=['put'])
def editWorkOrderItem():
    ''' 新增工单详情数据 '''
    uv = WorkOrderView()
    result = uv.editWorkOrderItem(request.json)
    return jsonify(result)


# end
# add cth 2020年12月1日16:57:29 start
# 增加修改试卷基本信息功能
@app.route('/essc/api/workorder/removeitem', methods=['POST'])
def removeWorkOrderItem():
    ''' 删除工单详情数据 '''
    uv = WorkOrderView()
    result = uv.removeWorkOrderItem(request.json)
    print(result)
    return jsonify(result)


# end
# add cth 2021年1月20日14:24:04 start
# 增加上传工单功能
@app.route('/essc/api/workorderdetailform/annex/upload/<workorderid>/<id>', methods=['POST'])
def uploadWorkOrderDetailFormAnnex(workorderid, id):
    """上传工单附件"""
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        if request.method == 'POST' and 'file' in request.files:
            file = request.files['file']
            print(file.filename)
            mime = file.filename.split('.')[1].lower()
            path = UPLOAD_PATH + "/workorderdetailform/annex/"

            path = path + workorderid
            path = path + "/"
            path = path + id + "/"
            filename = path + file.filename
            if not os.path.exists(filename):
                returnname = file.filename
                #             filename = path + id + "." + mime
                #             returnname = id + "." + mime
                my_path = Path(path)
                if not my_path.exists():
                    # 指定的文件或目录不存在:
                    os.makedirs(path)
        file.save(filename)
        return jsonify({"code": 200,
                        "message": "上传成功！",
                        # "data":{"name":file.filename,"url":API_TRANSFORM_ANNEX_DOWNLOAD +id+"." + mime}})
                        "data": {"name": returnname, "url": "", "mine": mime}})
    else:
        return jsonify(aouth)


# add cth 2021年1月22日09:59:18 start
# 增加下载工单
@app.route('/essc/api/image/download/workorder/<workorderid>/<id>/<filename>/<token>', methods=['GET'])
def downloadWorkForm(workorderid, id, filename, token):
    """下载"""
    filename = urllib.parse.unquote(filename)

    # 验证TOKEN
    aouth = AouthView().auouthCheck(token)
    if aouth['code'] == 200:
        mdict = {
            'jpeg': 'image/jpeg',
            'jpg': 'image/jpeg',
            'png': 'image/png',
            'gif': 'image/gif'
        }
        mime = mdict[filename.split('.')[1].lower()]
        path = UPLOAD_PATH + "/" + UPLOAD_WORKORDER_PATH_ANNEX + "/" + workorderid + "/" + id + "/" + filename
        if not os.path.exists(path):
            # Res 是我自己定义的返回类，raw方法将数据组成字典返回
            return jsonify('image does not exists')
        with open(path, 'rb') as f:
            image = f.read()
        resp = Response(image, mimetype=mime)
        return resp
    else:
        return jsonify(aouth)


@app.route('/essc/api/keepaccount/querylist', methods=['POST'])
def queryKeepAccount():
    ''' 显示记账信息 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        uv = KeepAccountView()
        result = uv.queryKeepAccount(request.json)
        return jsonify(result)
    else:
        return jsonify(aouth)


@app.route('/essc/api/keepaccount/additem', methods=['post'])
def addKeepAccountItem():
    ''' 新增记账详情数据 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        uv = KeepAccountView()
        result = uv.addKeepAccountItem(request.json)
        return jsonify(result)
    else:
        return jsonify(aouth)


@app.route('/essc/api/keepaccount/removeitem', methods=['POST'])
def removeKeepAccountItem():
    ''' 删除代理记账详情数据 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        uv = KeepAccountView()
        result = uv.removeKeepAccountItem(request.json)
        return jsonify(result)
    else:
        return jsonify(aouth)


@app.route('/essc/api/keepaccount/edit', methods=['put'])
def editKeepAccountItem():
    ''' 记账重新分配修改 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        uv = KeepAccountView()
        result = uv.distributeKeepAccount(request.json)
        return jsonify(result)
    else:
        return jsonify(aouth)


# add cth 2021年2月20日10:29:45 start
# function
@app.route('/essc/api/keepaccount/add', methods=['post'])
def addKeepAccount():
    ''' 新增代理记账旧记录'''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        uv = KeepAccountView()
        result = uv.addAgentKeeping(request.json)
        return jsonify(result)
    else:
        return jsonify(aouth)


# end
@app.route('/essc/api/keepaccount/edititem', methods=['put'])
def editKeepAccountsItem():
    ''' 修改记账详情数据 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        uv = KeepAccountView()
        result = uv.editKeepAccountItem(request.json)
        return jsonify(result)
    else:
        return jsonify(aouth)

@app.route('/essc/api/keepaccount/getTaxtypeoptions', methods=['GET'])
def getTaxtypeoptions():
    ''' 取得所有税务类型 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        uv = KeepAccountView()
        result = uv.getTaxtypeoptions()
        return jsonify(result)
    else:
        return jsonify(aouth)

@app.route('/essc/api/keepaccount/getTCPS', methods=['GET'])
def getTCPS():
    ''' 取得所有税控盘类型 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        uv = KeepAccountView()
        result = uv.getTCPS()
        return jsonify(result)
    else:
        return jsonify(aouth)

@app.route('/essc/api/keepaccount/getSbgjjs', methods=['GET'])
def getSbgjjs():
    ''' 取得所有社保公积金类型 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        uv = KeepAccountView()
        result = uv.getSbgjjs()
        return jsonify(result)
    else:
        return jsonify(aouth)

@app.route('/essc/api/keepaccount/updateTypeBatch', methods=['put'])
def updateTypeBatch():
    ''' 修改记账类型数据 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        uv = KeepAccountView()
        result = uv.updateTypeBatch(request.json)
        return jsonify(result)
    else:
        return jsonify(aouth)

@app.route('/essc/api/keepaccount/removesummary', methods=['POST'])
def removeKeepAccount():
    ''' 删除代理记账数据 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        uv = KeepAccountView()
        result = uv.removeKeepAccount(request.json)
        return jsonify(result)
    else:
        return jsonify(aouth)


# add cth 2021年1月20日14:24:04 start
# 增加上传工单功能
@app.route('/essc/api/keepaccountdetailform/annex/upload/<keepaccountid>/<id>', methods=['POST'])
def uploadKeepAccountDetailFormAnnex(keepaccountid, id):
    """上传工单附件"""
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        if request.method == 'POST' and 'file' in request.files:
            file = request.files['file']
            print(file.filename)
            mime = file.filename.split('.')[1].lower()
            path = UPLOAD_PATH + "/keepaccountdetailform/annex/"

            path = path + keepaccountid
            path = path + "/"
            path = path + id + "/"
            filename = path + file.filename
            if not os.path.exists(filename):
                returnname = file.filename
                #             filename = path + id + "." + mime
                #             returnname = id + "." + mime
                my_path = Path(path)
                if not my_path.exists():
                    # 指定的文件或目录不存在:
                    os.makedirs(path)
        file.save(filename)
        return jsonify({"code": 200,
                        "message": "上传成功！",
                        # "data":{"name":file.filename,"url":API_TRANSFORM_ANNEX_DOWNLOAD +id+"." + mime}})
                        "data": {"name": returnname, "url": "", "mine": mime}})
    else:
        return jsonify(aouth)


# end
# add cth 2021年1月22日09:59:18 start
# 增加下载工单
@app.route('/essc/api/image/download/keepaccount/<keepaccountid>/<id>/<filename>/<token>', methods=['GET'])
def downloadKeepAccount(keepaccountid, id, filename, token):
    """下载"""
    filename = urllib.parse.unquote(filename)

    # 验证TOKEN
    aouth = AouthView().auouthCheck(token)
    if aouth['code'] == 200:
        mdict = {
            'jpeg': 'image/jpeg',
            'jpg': 'image/jpeg',
            'png': 'image/png',
            'gif': 'image/gif'
        }
        mime = mdict[filename.split('.')[1].lower()]
        path = UPLOAD_PATH + "/" + UPLOAD_KEEPACCOUNT_PATH_ANNEX + "/" + keepaccountid + "/" + id + "/" + filename
        print(path)
        if not os.path.exists(path):
            # Res 是我自己定义的返回类，raw方法将数据组成字典返回
            return jsonify('image does not exists')
        with open(path, 'rb') as f:
            image = f.read()
        resp = Response(image, mimetype=mime)
        return resp
    else:
        return jsonify(aouth)


# end
# add cth 2021年1月28日14:54:34 start
# 增加读入个人试卷功能
@app.route('/essc/api/testpaperview/brushtestpaper', methods=['POST'])
def BrushPersonTestPaper():
    ''' 显示个人试卷'''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        uv = TestPaperView()
        result = uv.brush(request.json)
        return jsonify(result)
    else:
        return jsonify(aouth)


# end

# add cth 2021年2月1日15:55:28 start
# 增加取得会计部成员功能
@app.route('/essc/api/user/accountant', methods=['get'])
def getAccountant():
    '''取得会计部成员 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        uv = UserView()
        result = uv.getAccountant()
    else:
        return jsonify(aouth)
    return jsonify(result)


# end
# add cth 2021年2月2日11:15:11 start
# 增加工单批量删除
@app.route('/essc/api/workorder/removemul', methods=['post'])
def removeMulWorkprder():
    ''' 多选删除 '''
    # 验证TOKEN
    result = []
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        uv = WorkOrderView()
        result = uv.removeMulWorkOrder(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


# end
# add cth 2021年2月2日11:15:11 start
# 增加工单批量删除
@app.route('/essc/api/keepaccount/removemul', methods=['post'])
def removeMulKeepAccount():
    ''' 多选删除 '''
    # 验证TOKEN
    result = []
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        uv = KeepAccountView()
        result = uv.removeMulKeepAccount(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


# end
# add cth 2021年2月2日15:12:49 start
# 增加显示优惠券功能
@app.route('/essc/api/discountlist/querylist', methods=['POST'])
def queryDiscountList():
    ''' 显示优惠券信息 '''
    uv = DisCountListView()
    result = uv.queryDiscountList(request.json)
    return jsonify(result)


# end
# add cth 2021年2月2日15:12:49 start
# 增加驳回优惠单功能
@app.route('/essc/api/discountform/nopass', methods=['PUT'])
def nopassdiscountForm():
    '''驳回优惠单 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = DisCountListView()
        result = view.nopass(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


# end
# add cth 2021年2月2日15:12:49 start
# 增加通过优惠单功能
@app.route('/essc/api/discountform/audit', methods=['PUT'])
def auditdiscountForm():
    '''审核流转单 '''
    # 验证TOKEN
    print(request.json)
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = DisCountListView()
        result = view.approve(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/transform/checkfirst/<applicantid>', methods=['GET'])
def checkFirstDiscountForm(applicantid):
    '''检查是否是第一个流转单，返回count '''
    # 验证TOKEN
    print(request.json)
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = TransFormView()
        result = view.checkFirstForm(applicantid)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/borrow/query', methods=['POST'])
def queryBorrow():
    '''添加借支单信息 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = BorrowView()
        result = view.query(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/borrow/add', methods=['PUT'])
def addBorrow():
    '''添加借支单信息 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = BorrowView()
        result = view.add(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/borrow/update', methods=['PUT'])
def updateBorrow():
    '''更新借支单信息 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = BorrowView()
        result = view.update(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/borrow/delete', methods=['PUT'])
def deleteBorrow():
    ''' 作废'''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = BorrowView()
        result = view.delete(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/borrow/updateallannex', methods=['PUT'])
def updateBorrowALLAnnex():
    '''更新借支单支付截图信息 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = BorrowView()
        result = view.updateAllAnnex(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/borrow/annex/upload/<borrowformid>', methods=['POST'])
def uploadBorrowAnnex(borrowformid):
    """上传借支单附件"""
    #     # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        if request.method == 'POST' and 'file' in request.files:
            file = request.files['file']
            mime = file.filename.split('.')[1].lower()
            path = UPLOAD_PATH + "/borrow/annex/" + borrowformid
            filename = path + "/" + file.filename
            if not Path(path).exists():
                # 指定的文件或目录不存在:
                os.makedirs(path)
        file.save(filename)
        view = BorrowView()
        view.updateAnnex(file.filename, borrowformid)
        return jsonify({"code": 200,
                        "message": "上传成功！",
                        "data": {"name": file.filename,
                                 "url": API_BORROWFORM_ANNEX_DOWNLOAD + borrowformid + "/" + file.filename,
                                 "mine": mime}})
    else:
        return jsonify(aouth)


@app.route('/essc/api/borrow/annex/<borrowformid>/<filename>', methods=['GET'])
def downloadBorrowAnnex(borrowformid, filename):
    """下载证件照"""
    filename = urllib.parse.unquote(filename)

    # 验证TOKEN

    #     aouth = AouthView().auouthCheck(token)
    #     if aouth['code']==200:
    mdict = {
        'jpeg': 'image/jpeg',
        'jpg': 'image/jpeg',
        'png': 'image/png',
        'gif': 'image/gif'
    }
    mime = mdict[filename.split('.')[1].lower()]
    path = DOWNLOAD_PATH_BORROW_ANNEX + "/" + borrowformid + "/" + filename
    if not os.path.exists(path):
        # Res 是我自己定义的返回类，raw方法将数据组成字典返回
        return jsonify('image does not exists')
    with open(path, 'rb') as f:
        image = f.read()
    resp = Response(image, mimetype=mime)
    return resp


#     else:
#         return jsonify(aouth)
# add cth 2021年2月3日15:26:48 start
# 增加通过优惠单功能
@app.route('/essc/api/mycustomercompany/<userid>', methods=['GET'])
def getMycustomerInfo(userid):
    '''用户应用程序取得 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        uv = MyCustomerView()
        result = uv.getMycustomercompany(userid)
    else:
        return jsonify(aouth)
    return jsonify(result)


# end
# add cth 2021年2月3日16:10:11 start
# 增加驳回优惠单功能
@app.route('/essc/api/discountform/add', methods=['post'])
def applydiscountForm():
    '''申请优惠单 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = DisCountListView()
        result = view.apply(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/payform/query', methods=['POST'])
def queryPayForm():
    '''添加借支单信息 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = PayFormView()
        result = view.query(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/payform/add', methods=['PUT'])
def addPayForm():
    '''添加借支单信息 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = PayFormView()
        result = view.add(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/payform/update', methods=['PUT'])
def updatePayForm():
    '''更新借支单信息 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = PayFormView()
        result = view.update(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/payform/delete', methods=['PUT'])
def deletePayForm():
    ''' 作废'''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = PayFormView()
        result = view.delete(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/payform/updateallannex', methods=['PUT'])
def updatePayFormALLAnnex():
    '''更新借支单支付截图信息 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = PayFormView()
        result = view.updateAllAnnex(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/payform/annex/upload/<payformid>', methods=['POST'])
def uploadPayFormAnnex(payformid):
    """上传借支单附件"""
    #     # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        if request.method == 'POST' and 'file' in request.files:
            file = request.files['file']
            mime = file.filename.split('.')[1].lower()
            path = UPLOAD_PATH + "/payform/annex/" + payformid
            filename = path + "/" + file.filename
            if not Path(path).exists():
                # 指定的文件或目录不存在:
                os.makedirs(path)
        file.save(filename)
        view = PayFormView()
        view.updateAnnex(file.filename, payformid)
        return jsonify({"code": 200,
                        "message": "上传成功！",
                        "data": {"name": file.filename,
                                 "url": API_PAYFORM_ANNEX_DOWNLOAD + payformid + "/" + file.filename, "mine": mime}})
    else:
        return jsonify(aouth)


@app.route('/essc/api/payform/annex/<payformid>/<filename>', methods=['GET'])
def downloadPayFormAnnex(payformid, filename):
    """下载证件照"""
    filename = urllib.parse.unquote(filename)

    # 验证TOKEN
    #     aouth = AouthView().auouthCheck(token)
    #     if aouth['code']==200:
    mdict = {
        'jpeg': 'image/jpeg',
        'jpg': 'image/jpeg',
        'png': 'image/png',
        'gif': 'image/gif'
    }
    mime = mdict[filename.split('.')[1].lower()]
    path = DOWNLOAD_PATH_PAYFORM_ANNEX + "/" + payformid + "/" + filename
    if not os.path.exists(path):
        # Res 是我自己定义的返回类，raw方法将数据组成字典返回
        return jsonify('image does not exists')
    with open(path, 'rb') as f:
        image = f.read()
    resp = Response(image, mimetype=mime)
    return resp


#     else:
#         return jsonify(aouth)

# end
@app.route('/essc/api/supplier/list', methods=['GET'])
def getSupplierList():
    '''取得供应列表 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = SupplierView()
        result = view.list()
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/expenseform/query', methods=['POST'])
def queryExpenseForm():
    '''添加借支单信息 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = ExpenseFormView()
        result = view.query(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/expenseform/add', methods=['PUT'])
def addExpenseForm():
    '''添加借支单信息 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = ExpenseFormView()
        result = view.add(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/expenseform/update', methods=['PUT'])
def updateExpenseForm():
    '''更新借支单信息 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = ExpenseFormView()
        result = view.update(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/expenseform/delete', methods=['PUT'])
def deleteExpenseForm():
    ''' 作废'''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = ExpenseFormView()
        result = view.delete(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/expenseform/updateallannex', methods=['PUT'])
def updateExpenseFormALLAnnex():
    '''更新借支单支付截图信息 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = ExpenseFormView()
        result = view.updateAllAnnex(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/expenseform/annex/upload/<expenseformid>', methods=['POST'])
def uploadExpenseFormAnnex(expenseformid):
    """上传借支单附件 """
    #     # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        if request.method == 'POST' and 'file' in request.files:
            file = request.files['file']
            mime = file.filename.split('.')[1].lower()
            path = UPLOAD_PATH + "/expenseform/annex/" + expenseformid
            filename = path + "/" + file.filename
            if not Path(path).exists():
                # 指定的文件或目录不存在:
                os.makedirs(path)
        file.save(filename)
        view = ExpenseFormView()
        view.updateAnnex(file.filename, expenseformid)
        return jsonify({"code": 200,
                        "message": "上传成功！",
                        "data": {"name": file.filename,
                                 "url": API_EXPENSEFORM_ANNEX_DOWNLOAD + expenseformid + "/" + file.filename,
                                 "mine": mime}})
    else:
        return jsonify(aouth)


@app.route('/essc/api/expenseform/annex/<expenseformid>/<filename>', methods=['GET'])
def downloadExpenseFormAnnex(expenseformid, filename):
    """下载"""
    # 验证TOKEN
    #     aouth = AouthView().auouthCheck(token)
    #     if aouth['code']==200:
    #     mdict = {
    #         'jpeg': 'image/jpeg',
    #         'jpg': 'image/jpeg',
    #         'png': 'image/png',
    #         'gif': 'image/gif'
    #     }
    # mime = mdict[filename.split('.')[1].lower()]
    filename = urllib.parse.unquote(filename)
    path = DOWNLOAD_PATH_EXPENSEFORM_ANNEX + "/" + expenseformid + "/" + filename
    if not os.path.exists(path):
        # Res 是我自己定义的返回类，raw方法将数据组成字典返回
        return jsonify('文件不存在。')
    # with open(path, 'rb') as f:
    #     image = f.read()

    res = make_response(send_file(path))
    # 自定义的一个header，方便前端取到名字
    res.headers['filename'] = quote(filename.encode('utf-8'))
    return res
    # resp = Response(image, mimetype=mime)
    # return resp


#     else:
#         return jsonify(aouth)

# add cth 2021年2月3日17:08:33 start
# 增加优惠券作废
@app.route('/essc/api/discount/remove', methods=['put'])
def removeDiscountList():
    '''作废优惠单 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = DisCountListView()
        result = view.remove(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


# end

# add cth 2021年1月18日10:40:40 start
# 增加显示内部工单信息功能
@app.route('/essc/api/innerworkorder/querylist', methods=['POST'])
def queryInnerWorkOrder():
    ''' 显示内部工单信息 '''
    uv = InnerWorkOrderView()
    result = uv.queryInnerWorkOrder(request.json)
    return jsonify(result)


# end
# add 2021年2月4日11:40:47 start
# 增加修改在分配功能
@app.route('/essc/api/innerworkorder/edit', methods=['put'])
def editInnerWorkOrder():
    ''' 内部工单重新分配修改 '''
    uv = InnerWorkOrderView()
    result = uv.distributeInnerWorkOrder(request.json)
    return jsonify(result)


# end
# add 2021年2月4日14:15:58 start
# 增加添加内部工单功能
@app.route('/essc/api/innerworkorder/add', methods=['post'])
def addInnerWorkOrder():
    ''' 内部工单新增 '''
    uv = InnerWorkOrderView()
    result = uv.addInnerWorkOrder(request.json)
    return jsonify(result)


# end
# add 2021年2月4日11:49:55 start
# 增加新增工单详情数据
@app.route('/essc/api/innerworkorder/additem', methods=['post'])
def addInnerWorkOrderItem():
    ''' 新增内部工单详情数据 '''
    uv = InnerWorkOrderView()
    result = uv.addInnerWorkOrderItem(request.json)
    return jsonify(result)


# end
# add 2021年2月4日11:49:59 start
# 增加新增工单详情数据
@app.route('/essc/api/innerworkorder/edititem', methods=['put'])
def editInnerWorkOrderItem():
    ''' 新增工单详情数据 '''
    uv = InnerWorkOrderView()
    result = uv.editInnerWorkOrderItem(request.json)
    return jsonify(result)


# end
# add cth 2021年2月4日11:52:21 start
# 增加删除工单详情功能
@app.route('/essc/api/innerworkorder/removeitem', methods=['POST'])
def removeInnerWorkOrderItem():
    ''' 删除工单详情数据 '''
    uv = InnerWorkOrderView()
    result = uv.removeInnerWorkOrderItem(request.json)
    print(result)
    return jsonify(result)


# end
# add cth 2021年1月20日14:24:04 start
# 增加上传工单功能
@app.route('/essc/api/innerworkorderdetailform/annex/upload/<innerworkorderid>/<id>', methods=['POST'])
def uploadInnerWorkOrderDetailFormAnnex(innerworkorderid, id):
    """上传工单附件"""
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        if request.method == 'POST' and 'file' in request.files:
            file = request.files['file']
            mime = file.filename.split('.')[1].lower()
            path = UPLOAD_PATH + "/innerworkorderdetailform/annex/"

            path = path + innerworkorderid
            path = path + "/"
            path = path + id + "/"
            filename = path + file.filename
            if not os.path.exists(filename):
                returnname = file.filename
                my_path = Path(path)
                if not my_path.exists():
                    # 指定的文件或目录不存在:
                    os.makedirs(path)
        file.save(filename)
        return jsonify({"code": 200,
                        "message": "上传成功！",
                        "data": {"name": returnname, "url": "", "mine": mime}})
    else:
        return jsonify(aouth)


# end
# add cth 2021年2月4日12:59:29 start
# 增加下载工单
@app.route('/essc/api/image/download/innerworkorder/<innerworkorderid>/<id>/<filename>/<token>', methods=['GET'])
def downloadInnerWorkForm(innerworkorderid, id, filename, token):
    """下载"""
    filename = urllib.parse.unquote(filename)

    # 验证TOKEN
    aouth = AouthView().auouthCheck(token)
    if aouth['code'] == 200:

        mdict = {
            'jpeg': 'image/jpeg',
            'jpg': 'image/jpeg',
            'png': 'image/png',
            'gif': 'image/gif'
        }
        mime = mdict[filename.split('.')[1].lower()]
        path = UPLOAD_PATH + "/" + UPLOAD_INNERWORKORDER_PATH_ANNEX + "/" + innerworkorderid + "/" + id + "/" + filename
        if not os.path.exists(path):
            # Res 是我自己定义的返回类，raw方法将数据组成字典返回
            return jsonify('image does not exists')
        with open(path, 'rb') as f:
            image = f.read()
        resp = Response(image, mimetype=mime)
        return resp
    else:
        return jsonify(aouth)


# end
# add cth 2021年2月4日13:06:40 start
# 增加工单批量删除
@app.route('/essc/api/innerworkorder/removemul', methods=['post'])
def removeMulInnerWorkprder():
    ''' 多选删除 '''
    # 验证TOKEN
    result = []
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        uv = InnerWorkOrderView()
        result = uv.removeMulInnerWorkOrder(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


# end

@app.route('/essc/api/discountlist/getlist/<id>', methods=['GET'])
def getDiscountList(id):
    ''' 显示优惠券信息 '''
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = DisCountListView()
        result = view.getList(id)
    else:
        return jsonify(aouth)
    return jsonify(result)


# add cth 2021年2月20日10:25:57 start
# 增加代理记账查询客户名字
@app.route('/essc/api/keepaccount/querycustomer/<query>', methods=['GET'])
def queryKeepAccountCustomer(query):
    ''' 查询客户名字 '''
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = KeepAccountView()
        result = view.queryKeepAccountCustomer(query)
    else:
        return jsonify(aouth)
    return jsonify(result)


# end
# add cth 2021年2月22日14:58:33 start
# 审核内部工单
@app.route('/essc/api/innerworkorder/audit', methods=['PUT'])
def auditinnerWorkOrder():
    '''审核流转单 '''
    # 验证TOKEN
    print(request.json)
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = InnerWorkOrderView()
        result = view.audit(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


# end
# add cth 2021年2月22日15:33:00 start
# 驳回内部事务单
@app.route('/essc/api/innerworkorder/nopass', methods=['PUT'])
def nopassinnerWorkOrder():
    '''驳回流转单 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = InnerWorkOrderView()
        result = view.nopass(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


# end
# add cth 2021年2月26日13:25:53 start
# 帮助文档读取树状图功能
@app.route('/essc/api/help/loadtree', methods=['POST'])
def readHelpTreeJson():
    ''' 读取json '''
    uv = HelpJsonView()
    result = uv.readhelptree()
    return jsonify(result)


# end
# add cth 2021年3月1日15:59:372 start
# 导出
@app.route('/essc/api/myregistrator/export', methods=['PUT'])
def exportMyregistrator():
    ''' 导出 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = MyRegistratorView()
        result = view.export(request.json)
    else:
        return jsonify(aouth)
    return result


@app.route('/essc/api/transformrecorder/annex/upload/<id>', methods=['POST'])
def uploadTransFormRecorderAnnex(id):
    """上传收款截图"""
    #     # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        if request.method == 'POST' and 'file' in request.files:
            file = request.files['file']
            mime = file.filename.split('.')[1].lower()
            path = UPLOAD_PATH + "/transformrecorder/annex/" + id
            filename = path + "/" + file.filename
            if not Path(path).exists():
                # 指定的文件或目录不存在:
                os.makedirs(path)
        file.save(filename)
        return jsonify({"code": 200,
                        "message": "上传成功！",
                        "data": {"name": file.filename,
                                 "url": API_TRANSFORMRECORDER_ANNEX_DOWNLOAD + id + "/" + file.filename, "mine": mime}})


@app.route('/essc/api/transformrecorder/annex/<id>/<filename>', methods=['GET'])
def downloadtransformrecorderAnnex(id, filename):
    """下载证件照"""
    # 验证TOKEN
    #     aouth = AouthView().auouthCheck(token)
    #     if aouth['code']==200:
    filename = urllib.parse.unquote(filename)

    mdict = {
        'jpeg': 'image/jpeg',
        'jpg': 'image/jpeg',
        'png': 'image/png',
        'gif': 'image/gif'
    }
    arrstr = filename.split('.')
    mime = mdict[arrstr[len(arrstr)-1].lower()]
    path = DOWNLOAD_PATH_TRANSFORMRECORDER_ANNEX + "/" + id + "/" + filename
    if not os.path.exists(path):
        # Res 是我自己定义的返回类，raw方法将数据组成字典返回
        return jsonify('文件没有找到。')
    with open(path, 'rb') as f:
        image = f.read()
    resp = Response(image, mimetype=mime)
    return resp


@app.route('/essc/api/transformrecorder/add', methods=['PUT'])
def addTransFormRecorder():
    ''' 添加收款记录 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = TransFormRecorderView()
        result = view.add(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/transformrecorder/edit', methods=['PUT'])
def editTransFormRecorder():
    ''' 添加收款记录 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = TransFormRecorderView()
        result = view.update(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/transformrecorder/delete/<id>', methods=['PUT'])
def deleteTransFormRecorder(id):
    ''' 删除收款记录 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = TransFormRecorderView()
        result = view.delete(id)
    else:
        return jsonify(aouth)
    return jsonify(result)


# end
# add cth 2021年3月10日11:29:00 start
# 增加上传工单功能
@app.route('/essc/api/innerworkorderform/annex/upload/<id>', methods=['POST'])
def uploadInnerWorkOrderFormAnnex(id):
    """上传工单附件"""
    # 验证TOKEN
    print(id)
    id = id if (id is not None) else 0
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        if request.method == 'POST' and 'file' in request.files:
            file = request.files['file']
            mime = file.filename.split('.')[1].lower()
            path = UPLOAD_PATH + "/innerworkorderform/annex/"
            filename = path + file.filename
            returnname = file.filename
            if not os.path.exists(filename):
                returnname = file.filename
                my_path = Path(path)
                if not my_path.exists():
                    # 指定的文件或目录不存在:
                    os.makedirs(path)
        file.save(filename)
        return jsonify({"code": 200,
                        "message": "上传成功！",
                        "data": {"name": returnname, "url": "", "mine": mime}})
    else:
        return jsonify(aouth)


# end

@app.route('/essc/api/transform/getlast/<id>', methods=['POST'])
def getLastTransForm(id):
    '''取得最后一次驳回的流转单信息 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = TransFormView()
        result = view.getLast(id)
    else:
        return jsonify(aouth)
    return jsonify(result)


# add cth 2021年3月10日11:29:00 start
# 增加上传工单功能
@app.route('/essc/api/workorderinner/annex/download', methods=["post"])
def downloadWorkOrderAnnex():
    '''下载附件 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.json["token"])  # request.json["params"]["token"]
    if aouth['code'] == 200:
        filename = request.json["downloadname"]  # 文件名
        filepath = DOWNLOAD_PATH_INNERWORKORDER_ANNEX
        filepath = filepath + '/' + filename
        res = make_response(send_file(filepath))
        # 自定义的一个header，方便前端取到名字
        res.headers['filename'] = quote(filename.encode('utf-8'))
        return res

    else:
        return jsonify(aouth)


# end


# add ccj、 2021年3月12日13:39:47 start
# 增加修改密码功能
@app.route('/essc/api/user/updatepassword', methods=['PUT'])
def updateUserPassword():
    ''' 更新 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        uv = UserView()
        result = uv.updateUserPassword(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


# add cth 2021年3月12日10:06:55 start
# 增加取得服务名称功能
@app.route('/essc/api/questionbankview/testtype', methods=['get'])
def getTestType():
    '''取得考试分类 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = QuestionBankView()
        result = view.getTestType()
    else:
        return jsonify(aouth)
    return jsonify(result)


# end
# add cth 2021年3月17日10:45:33 start
# function
@app.route('/essc/api/workorder/add', methods=['post'])
def addWorkOrder():
    ''' 新增工单旧记录'''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        uv = WorkOrderView()
        result = uv.addWorkOrder(request.json)
        return jsonify(result)
    else:
        return jsonify(aouth)


# end
# add cth 2021年3月17日10:45:33 start
# function
@app.route('/essc/api/keepaccount/editcus', methods=['put'])
def editKeepAccountCus():
    ''' 记账修改客户相关信息和续费情况 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        uv = KeepAccountView()
        result = uv.editCusKeepAccount(request.json)
        return jsonify(result)
    else:
        return jsonify(aouth)


# end
# add cth 2021年3月24日16:53:16 start
# 增加显示档案功能
@app.route('/essc/api/document/querylist', methods=['POST'])
def queryDocumentList():
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        uv = DocumentView()
        result = uv.queryDocument(request.json)
        return jsonify(result)
    else:
        return jsonify(aouth)


# end
# add cth 2021年3月26日15:31:10 start
@app.route('/essc/api/servicetree/get', methods=['GET'])
def getServiceTree():
    ''' 取得服务项目树状图'''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = ServiceView()
        result = view.getServiceTree()
    else:
        return jsonify(aouth)
    return jsonify(result)


# end
@app.route('/essc/api/servicedetail/get/methodpost', methods=['POST'])
def getServicesDetailPost():
    ''' 取得服务项目明细(post方法)'''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = ServiceView()
        result = view.getServicesDetail(request.json)
    else:
        return jsonify(aouth)

    ''' 显示优惠券信息 '''
    # end

    return jsonify(result)


# add cth 2021年3月29日09:25:59 start
@app.route('/essc/api/service/add', methods=['POST'])
def addServiceDetail():
    ''' 新增服务详情'''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = ServiceView()
        result = view.addServiceDetail(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


# end
# add cth 2021年3月29日14:17:04 start
@app.route('/essc/api/service/addname', methods=['POST'])
def addService():
    ''' 新增服务'''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = ServiceView()
        result = view.addService(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


# end
# add cth 2021年3月30日09:48:39 start
@app.route('/essc/api/service/edit', methods=['PUT'])
def editServiceDetail():
    ''' 新增服务详情'''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = ServiceView()
        result = view.editServiceDetail(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


# end
# add cth 2021年3月30日10:28:25 start
@app.route('/essc/api/service/editname', methods=['PUT'])
def editService():
    ''' 新增服务'''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = ServiceView()
        result = view.editService(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


# end
# end


@app.route('/essc/api/uploadframe/query', methods=['POST'])
def getDirList():
    ''' 取得目标目录下的文件和目录列表 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = DocumentView()
        result = view.getDirList(request.json)
        return jsonify(result)
    else:
        return jsonify(aouth)


@app.route('/essc/api/uploadframe/mkdir', methods=['put'])
def mkDir():
    ''' 创建目录'''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = DocumentView()
        result = view.mkDir(request.json)
        return jsonify(result)
    else:
        return jsonify(aouth)


@app.route('/essc/api/uploadframe/rmtree', methods=['put'])
def rmTree():
    ''' 删除目录'''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = DocumentView()
        result = view.rmTree(request.json)
        return jsonify(result)
    else:
        return jsonify(aouth)


@app.route('/essc/api/uploadframe/download', methods=['post'])
def downloadDocument():
    '''下载客户档案 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        param = request.json
        dirpath = UPLOAD_PATH + "/" + param['curdir'] + "/" + param['name']
        res = make_response(send_file(dirpath))
        # 自定义的一个header，方便前端取到名字
        res.headers['filename'] = quote(param['name'].encode('utf-8'))
        return res
    else:
        return jsonify(aouth)


@app.route('/essc/api/uploadframe/upload', methods=['POST'])
def uploadDocument():
    """上传客户档案"""
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        if request.method == 'POST' and 'file' in request.files:
            file = request.files['file']
            path = UPLOAD_PATH + "/" + request.form['curdir']
            filename = path + "/" + file.filename
            if not Path(path).exists():
                # 指定的文件或目录不存在:
                os.makedirs(path)
        file.save(filename)
        return jsonify({"code": 200,
                        "message": "上传成功！"})
    else:
        return jsonify(aouth)


# add cth 2021年3月30日10:28:25 start
@app.route('/essc/api/keepaccount/batchnewcharger', methods=['put'])
def batchKeepAccountcharger():
    ''' 批量分配新负责人 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        uv = KeepAccountView()
        result = uv.batchKeepAccountCharger(request.json)
        return jsonify(result)
    else:
        return jsonify(aouth)


# add ccj、 2021年3月25日11:25:37 start
# 增加添加/删除部门或者分组
@app.route('/essc/api/user/addDeptGroup', methods=['post'])
def adddeptgroup():
    ''' 添加部门或者分组'''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        uv = UserView()
        result = uv.addDeptGroup(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/user/removedept', methods=['post'])
def removeUserDept():
    ''' 删除部门或者分组'''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        uv = UserView()
        result = uv.removeUserDept(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


# end

# add ccj 2021年4月13日11:10:25 start
# 显示所有职位
@app.route('/essc/api/allposition', methods=['GET'])
def getAllPosition():
    '''所有职位列表取得 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        av = PositionView()
        result = av.getAllPosition()
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/phoneapps/get/<id>', methods=['GET'])
def getPhoneApps(id):
    '''手机应用程序取得 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        av = UserView()
        result = av.getPhoneApps(id)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/ph_approval/query', methods=['POST'])
def queryApproval():
    ''' 审批列表 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = ApprovalView()
        result = view.query(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/test/inittype', methods=['GET'])
def initTestType():
    ''' 获取题库大分类 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = QuestionBankView()
        result = view.initTestType()
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/test/initsubtype/<type>', methods=['GET'])
def initTestSubType(type):
    ''' 获取题库小分类 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = QuestionBankView()
        result = view.initTestSubType(type)
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/customer/gettaxtyps', methods=['GET'])
def getTaxTyps():
    """取得现有数据中的税务类型"""
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = CustomerView()
        result = view.getTaxTyps()
    else:
        return jsonify(aouth)
    return jsonify(result)


@app.route('/essc/api/personalsales/query', methods=['POST'])
def getPSgetlist():
    """获取个人流转单销售详细"""
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = PersonalSalesView()
        result = view.query(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)

@app.route('/essc/api/personalsales/getTransFormDatas/<id>', methods=['POST'])
def getTransList(id):
    """获取流转单详细"""
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = PersonalSalesView()
        result = view.getTransFormDatas(id)
    else:
        return jsonify(aouth)
    return jsonify(result)

# authoritymanagement
@app.route('/essc/api/authoritymanagement/query', methods=['POST'])
def getAuthorityManagement():
    """获取部门权限详细"""
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = AuthorityManagementView()
        result = view.query(request.json)

    else:
        return jsonify(aouth)
    return jsonify(result)


# authoritymanagement
@app.route('/essc/api/authoritymanagement/update', methods=['POST'])
def updateAuthorityManagement():
    """获取部门权限详细"""
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = AuthorityManagementView()
        result = view.update(request.json)

    else:
        return jsonify(aouth)
    return jsonify(result)


# authoritymanagement
@app.route('/essc/api/authoritymanagement/insert', methods=['POST'])
def insertAuthorityManagement():
    """获取部门权限详细"""
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = AuthorityManagementView()
        result = view.insert(request.json)

    else:
        return jsonify(aouth)
    return jsonify(result)


# authoritymanagement
@app.route('/essc/api/authoritymanagement/deletet', methods=['POST'])
def deletetAuthorityManagement():
    """获取部门权限详细"""
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = AuthorityManagementView()
        result = view.deletet(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)

@app.route('/essc/api/invoicefunction/query', methods=['POST'])
def invoiceFunctionQuery():
    """主查询"""
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = InvoiceCompanyView()
        result = view.query(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)

@app.route('/essc/api/invoicefunction/editClickUpdate', methods=['POST'])
def invoiceFunctionEdit():
    """编辑"""
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = InvoiceCompanyView()
        result = view.editClickUpdate(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)

@app.route('/essc/api/invoicefunction/submitDeleteClick', methods=['POST'])
def invoiceFunctionDeleteClick():
    """减票"""
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = InvoiceCompanyView()
        result = view.deleteClick(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)

@app.route('/essc/api/invoicefunction/submitInsertClick', methods=['POST'])
def invoiceFunctionInsertClick():
    """增票"""
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = InvoiceCompanyView()
        result = view.insertClick(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)

@app.route('/essc/api/invoicefunction/columnsQuery', methods=['POST'])
def invoiceFunctionColumnsQuery():
    """查询该公司开票记录的方法"""
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = InvoiceCompanyView()
        result = view.columnsQuery(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)

@app.route('/essc/api/invoicefunction/updatestate', methods=['POST'])
def invoiceFunctionUpdatestate():
    """作废方法"""
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = InvoiceCompanyView()
        result = view.updatestate(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)

@app.route('/essc/api/invoicefunction/insertCompany', methods=['POST'])
def invoiceFunctionInsertCompany():
    """发票新增"""
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = InvoiceCompanyView()
        result = view.insertCompany(request.json)
    else:
        return jsonify(aouth)
    return jsonify(result)

@app.route('/essc/api/invoicefunction/getCompanys', methods=['POST'])
def invoiceFunctionGetCompanys():
    """获取可以新增公司"""
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = InvoiceCompanyView()
        result = view.getCompanys()
    else:
        return jsonify(aouth)
    return jsonify(result)

@app.route('/essc/api/invoicefunction/import', methods=['POST'])
def InvioceFunctionImport():
    """导入原肵统计表"""
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = InvoiceCompanyView()
        result = view.importfile(request)
    else:
        return jsonify(aouth)
    return jsonify(result)

@app.route('/essc/api/invoicefunction/getUsers', methods=['POST'])
def InvioceFunctionGetUsers():
    """导入原肵统计表"""
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        view = InvoiceCompanyView()
        result = view.getUsers()
    else:
        return jsonify(aouth)
    return jsonify(result)

@app.route('/essc/api/keepaccount/statusset', methods=['put'])
def statusset():
    ''' 状态设定 '''
    # 验证TOKEN
    aouth = AouthView().auouthCheck(request.headers.get('Token'))
    if aouth['code'] == 200:
        uv = KeepAccountView()
        result = uv.statusset(request.json)
        return jsonify(result)
    else:
        return jsonify(aouth)

if __name__ == '__main__':
    schedule = APScheduler()
    schedule.init_app(app)
    schedule.start()

    app.run(host='0.0.0.0', port=PORT, threaded=True, debug=True)


